package com.hanqian.kepler.core.service.core.impl;

import cn.hutool.core.convert.Convert;
import com.hanqian.kepler.common.base.dao.BaseDao;
import com.hanqian.kepler.common.base.service.BaseServiceImpl;
import com.hanqian.kepler.common.bean.result.AjaxResult;
import com.hanqian.kepler.core.dao.primary.core.TargetDescHistoryDao;
import com.hanqian.kepler.core.entity.primary.core.TargetDesc;
import com.hanqian.kepler.core.entity.primary.core.TargetDescHistory;
import com.hanqian.kepler.core.service.core.TargetDescHistoryService;
import com.hanqian.kepler.core.service.core.TargetDescZanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * newFile
 * ============================================================================
 * author : dzw
 * createDate:  2020/12/25 。
 * ============================================================================
 */
@Service
public class TargetDescHistoryServiceImpl extends BaseServiceImpl<TargetDescHistory, String> implements TargetDescHistoryService {

	@Autowired
	private TargetDescHistoryDao targetDescHistoryDao;
	@Autowired
	private TargetDescZanService targetDescZanService;

	@Override
	public BaseDao<TargetDescHistory, String> getBaseDao() {
		return targetDescHistoryDao;
	}

	@Override
	public AjaxResult saveHistoryVersion(TargetDesc targetDesc) {
		TargetDescHistory targetDescHistory = new TargetDescHistory();
		targetDescHistory.setTargetDescId(targetDesc.getId());
		targetDescHistory.setTargetDescDictName(targetDesc.getTargetDescDict()!=null ? targetDesc.getTargetDescDict().getName() : "");
		targetDescHistory.setContent(targetDesc.getContent());
		targetDescHistory.setExplanation(targetDesc.getExplanation());
		targetDescHistory.setIfYuan(targetDesc.getIfYuan());
		targetDescHistory.setYuan(targetDesc.getYuan());
		targetDescHistory.setVersion(targetDesc.getVersion());
		targetDescHistory.setVersionIndex(targetDesc.getVersionIndex());
		targetDescHistory.setZan(Convert.toStr(targetDescZanService.getZanCount(targetDesc)));
		targetDescHistory = save(targetDescHistory);
		return AjaxResult.successWithId("保存成功", targetDescHistory.getId());
	}
}
